import Flutter
import UIKit

public class SwiftUniqueIosDeviceIdPlugin: NSObject, FlutterPlugin {
    public static func register(with registrar: FlutterPluginRegistrar) {
        let channel = FlutterMethodChannel(name: "unique_ios_device_id", binaryMessenger: registrar.messenger())
        let instance = SwiftUniqueIosDeviceIdPlugin()
        registrar.addMethodCallDelegate(instance, channel: channel)
    }
    
    public func handle(_ call: FlutterMethodCall, result: @escaping FlutterResult) {
        // 如果是调用获取deviceID的方法
        if (call.method == "getDeviceId") {
            let key = call.arguments as? String
            handleGetDeviceId(result: result, key: key ?? "")
        } else {
            result(FlutterMethodNotImplemented)
        }
    }
    
    public func handleGetDeviceId(result: @escaping FlutterResult, key: String) {
        result(UUIDTool.getUUID(key))
    }
}
